package headfirst.observer;

import java.util.HashMap;
import java.lang.String;

class CountByCategory implements IntfObserver
{
	private HashMap<String, Integer> m_cateCountList;
	public CountByCategory()
	{
		this.m_cateCountList = new HashMap<String, Integer>();
	}

	public boolean doUpdate(String[] info)
	{	
		if(null==info)
		{
			return false;
		}
		if(3 > info.length)
		{
			return false;
		}
		if(null == info[2] || 0 == info[2].length())
		{
			return false;
		}
		String cid=info[2];
		if(null == this.m_cateCountList.get(cid))
		{
			this.m_cateCountList.put(cid, new Integer(1));
		}
		else
		{
			Integer tucount = (Integer)this.m_cateCountList.get(cid);
			this.m_cateCountList.put(cid, new Integer(tucount.intValue()+1));
		}
		return true;
	}
	
	public boolean showCountResult()
	{
		System.out.println("in func showCountResult");
		System.out.println("result size "+this.m_cateCountList.size());
		return true;
	}
}
